package com.wn.date20190820Socket;

import java.net.ServerSocket;
import java.net.Socket;

/**
 * 聊天服务器
 * 
 * @author song
 *
 */
public class ChatServer implements Runnable
{

	private static int port;

	public ChatServer(int port)
	{
		this.port = port;
	}

	public int getPort()
	{
		return port;
	}

	public void setPort(int port)
	{
		this.port = port;
	}

	@Override
	public void run()
	{
		try (ServerSocket sc = new ServerSocket(port);)
		{
			while (true)
			{
				Socket socket = sc.accept();
				new Thread(new SocketThread(socket)).start();
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}

	}

}
